package leetCode.competition;

import org.junit.Test;

import java.util.LinkedList;
import java.util.List;

public class Code_1707 {
    @Test
    public void test() {
        int[] nums = new int[]{5, 2, 4, 6, 6, 3};
        int[][] queries = new int[][]{{12, 4}, {8, 1}, {6, 3}};
        int[] result = maximizeXor(nums, queries);

        System.out.println(Integer.MAX_VALUE);
        System.out.println("Hello, World!");
    }

    public int[] maximizeXor(int[] nums, int[][] queries) {
        int[] tmp = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            tmp[i] = getResult(nums, queries[i]);
        }
        return tmp;
    }

    public int getResult(int[] nums, int[] query) {
        List<Integer> smaller = new LinkedList<Integer>();
        for (int num : nums) {
            if (query[1] >= num) {
                smaller.add(num);
            }
        }
        if (smaller.size() == 0) return -1;
        int max = -2147483648;
        for (Integer integer : smaller) {
            if ((integer ^ query[0]) > max) {
                max = integer ^ query[0];
            }
        }
        return max;
    }
}
